/**
 * @param {string} digits
 * @return {string[]}
 * https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
 */
 var letterCombinations = function(digits) {
    const  letterMap ={
        2 : "abc", // 2
        3 : "def", // 3
        4 : "ghi", // 4
        5 : "jkl", // 5
        6 : "mno", // 6
        7 : "pqrs", // 7
        8 : "tuv", // 8
        9 : "wxyz", // 9
    };
    let results = []
    let path = []

    function loop(index) {
        if(path.length === digits.length){
            results.push(path.join(''))
            return
        }
        for (let i = 0; i < letterMap[digits[index]].length; i++) {
            path.push(letterMap[digits[index]][i])
            loop(index + 1)
            path.pop()
        }
    }

    loop(0)

    console.log(results)
};


letterCombinations("234")